const lowdb =require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('db.json');

const shortid = require('shortid');

//获取db 对象
const db = lowdb(adapter);

//初始化数据
//db.defaults({ posts:[], user:{}}).write()

//写入数据
// db.get('posts').push({id:2,title:'今天天气还不错'}).write();

// //在前面加入
// db.get('posts').unshift({id:3,title:'今天天气还不错'}).write();

//获取数据
//console.log(db.get('posts').value());

//获取单条数据
let dantiao = db.get('posts').find({id:3}).value();
console.log(dantiao)

//删除数据
let res = db.get('posts').remove({id:1}).write();
console.log(res);

//跟新数据
db.get('posts').find({id:3}).assign({title:'今天下雨了'}).write();